{% extends 'base_template/adminBase.html' %}
{% load tags %}
{% block main_content %}
    <div class="card shadow">
        <div class="card-header py-3"><p class="text-primary m-0 fw-bold">{{ username }}</p></div>
        <div class="card-body">
            <div class="row">
                <div class="col-md-6 text-nowrap">
                    <div id="dataTable_length" class="dataTables_length" aria-controls="dataTable"></div>
                </div>
                <div class="col-md-6">
                    <div class="text-md-end dataTables_filter" id="dataTable_filter"></div>
                </div>
            </div>
            <div class="table-responsive table mt-2" id="dataTable" role="grid"
                 aria-describedby="dataTable_info">

                <form action="{% url 'adminComMgrStaffEdit' id=staff.id %}" method="post"
                      enctype="multipart/form-data">
                    {% csrf_token %}
                    <table class="table text-nowrap table-hover table-bordered" id="dataTable">
                        <thead>
                        <tr class="text-center">
                            <th>班级</th>
                            <th>课程</th>
                            <td>人数</td>
                        </tr>
                        </thead>
                        <tbody align="center">

                        {% for course in courses %}
                            <tr>
                                {% for foo in course.study_set.all %}
                                    {% if foo.staff.id == staff.id %}
                                        {% if forloop.counter == 1 %}
                                            <td>{{ course.study_set.all.0.student.inClass.name }}</td>
                                            <td>{{ course.name }}</td>
                                            <td>
                                                {{ course.study_set.all.count }}
                                            </td>
                                        {% endif %}
                                    {% endif %}
                                {% endfor %}
                            </tr>
                        {% endfor %}


                        </tbody>
                    </table>

                    <div class="row mb-3 table-responsive table mt-2" role="grid"
                         aria-describedby="dataTable_info">
                        <label class="text-center">修改表</label>
                        <table class="table text-nowrap table-responsive-sm">
                            <tbody>
                            <td><select name="class" id="class" class="select2-container--above text-center">
                                {% for name in stuClass.all %}
                                    <option value="{{ name.class_id }}">{{ name.name }}</option>
                                {% endfor %}
                            </select></td>
                            <td><select name="course" id="course" class="select2-container--above text-center">
                                {% for course in courses %}
                                    <option value="{{ course.id }}">{{ course.name }}</option>
                                {% endfor %}
                            </select></td>
                            <td>
                                <input type="submit" value="删除" class="btn btn-danger btn-outline-dark">
                            </td>
                            </tbody>
                        </table>
                    </div>

                    <div>
                        {% if messages %}
                            <div class="col-12">
                                {% for message in messages %}
                                    {% if message.tags == 'error' %}
                                        <div class="alert alert-danger"
                                             style="margin-top:10px">{{ message }}</div>
                                    {% endif %}
                                    {% if message.tags == 'success' %}
                                        <div class="alert alert-success"
                                             style="margin-top:10px">{{ message }}</div>
                                    {% endif %}
                                {% endfor %}
                            </div>
                        {% endif %}
                    </div>
                </form>
            </div>
        </div>
    </div>

{% endblock main_content %}